package com.goldsprite.infinityworld.screens.examples.ui;

import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.goldsprite.gdxcore.screens.GScreen;
import com.goldsprite.infinityworld.assets.GlobalAssets;

public class SplitPaneExampleScreen extends GScreen {
	private Stage stage;

	@Override
	public void create() {
		//获取皮肤以及list的背景作为table的背景
		Skin skin = new Skin(Gdx.files.internal(GlobalAssets.skinPath));
		// 设置字体和控件尺寸（通过skin文件的字体和样式设置）
		skin.getFont("font-button").getData().setScale(2.0f); // 放大字体2倍
		skin.getFont("font-label").getData().setScale(2.0f); // 放大字体2倍
		Drawable background = skin.getDrawable("list");

		//创建舞台
		stage = new Stage(getViewport());
		getImp().addProcessor(stage);

		//创建控制台布局
		Table consoleTable = new Table(skin);
		consoleTable.setBackground(background);
		consoleTable.add("consoleTable");

		//创建游戏布局
		Table gameTable = new Table(skin);
		gameTable.setBackground(background);
		//gameTable.add("gameTable");

		//创建游戏世界
		MyCustomActor gameWorld = new MyCustomActor();
		gameTable.add(gameWorld).expand().fill();

		//创建纵向分栏控制台在上游戏在下
		SplitPane splitPane = new SplitPane(consoleTable, gameTable, true, skin);
		splitPane.setFillParent(true);
		splitPane.setSplitAmount(0.3f);
		//添加到舞台
		stage.addActor(splitPane);
	}

	@Override
	public void render(float delta) {
		super.render(delta);

		//更新与绘制舞台
		stage.act(delta);
		stage.draw();
	}

	class MyCustomActor extends Actor {
		private Texture tex;

		public MyCustomActor() {
			tex = new Texture(GlobalAssets.logoPath);
		}

		@Override
		public void act(float delta) {
			super.act(delta);
		}

		@Override
		public void draw(Batch batch, float parentAlpha) {
			batch.draw(tex, getWidth()/2/2, getHeight()/2/2, getWidth()/2, getHeight()/2);
		}
	}
}
